package ro.isdc.vms.utils.timestamp;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

/**
 * Utility class for creation of timestamps.
 * 
 */
public class TimeStampUtil {

	/**
	 * Gets the curent time.
	 * 
	 * @return Timestamp with current date
	 */
	public static Timestamp getTimeStamp() {
		return new Timestamp(new Date().getTime());
	}

	/**
	 * Gets the oldest time (typically 01.01.1970)
	 */
	public static Timestamp getOldestTimeStamp() {
		return new Timestamp(0);
	}

	/**
	 * Gets the curent time plus or minus the noOfDays parameter depending if
	 * the noOfDays is positive or negative.
	 * 
	 * @param noOfDays
	 *            no of days to be added or substracted to the current time
	 * @return Timestamp
	 */
	public static Timestamp getTimestampAfterOrBeforeDays(final int noOfDays) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, noOfDays);
		return new Timestamp(calendar.getTimeInMillis());
	}

	/**
	 * Gets the number of days between two Date objects.
	 * 
	 * @param firstDate
	 *            the first date
	 * @param secondDate
	 *            the second date
	 * @return the number of days between the givend dates
	 */
	public static int getDaysBetween(final Date firstDate, final Date secondDate) {
		if (firstDate == null || secondDate == null) {
			return -1;
		}

		return TimeIntervalUtil.getMillisecondsInDays(secondDate.getTime()
				- firstDate.getTime());
	}

}
